﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;
using System.Data.SqlClient;
using System.Collections;
using System.Data;

namespace DAO
{
    public class XuatKhoDAO : DataProvider
    {
        public ArrayList GetDSPhieuXuatKho()
        {
            connect();
            string sql = "SELECT * FROM PhieuXuatKho";
            adapter = new SqlDataAdapter(sql, connection);
            DataSet dataset = new DataSet();
            adapter.Fill(dataset);
            ArrayList arr = ConvertDataSetToArrayList(dataset);
            disconnect();
            return arr;
        }

        protected override object GetDataFromDataRow(DataTable dt, int i)
        {
            XuatKhoDTO xkDTO = new XuatKhoDTO();
            xkDTO.XkID = int.Parse(dt.Rows[i][0].ToString());
            xkDTO.YcID = int.Parse(dt.Rows[i][1].ToString());
            xkDTO.NgayLap = DateTime.Parse(dt.Rows[i][2].ToString());
            xkDTO.NguoiLap = int.Parse(dt.Rows[i][3].ToString());
            xkDTO.TinhTrang = bool.Parse(dt.Rows[i][4].ToString());

            return (object)xkDTO;
        }

        public void XuatKho(XuatKhoDTO info)
        {
            connect();
            string sql1 = "UPDATE PhieuXuatKho SET tinh_trang = 'True' WHERE xuat_kho_id = "+ info.XkID;

            string sql2 = "SELECT * FROM ChiTietPhieuXuatKho WHERE xuat_kho_id = "+ info.XkID;
            disconnect();
        }

        //public void ThemPhieuXuatKho(XuatKhoDTO info)
        //{
        //    connect();
        //    string sql = "INSERT INTO PhieuXuatKho VALUES("+info.YcID+",'"+info.NgayLap+"',"+info.NguoiLap+")";
        //    executeNonQuery(sql);
        //    disconnect();
        //}

        //public int GetIDPhieuXK(int id)
        //{
        //    connect();
        //    string sql = "SELECT xuat_kho_id FROM PhieuXuatKho WHERE yeu_cau_id = " id ;
        //    SqlCommand cmd = new SqlCommand(sql,connection);
        //    SqlDataReader reader = cmd.ExecuteReader();
        //    int res = 0;
        //    while(reader.Read())
        //        res = reader.GetInt32(0);
        //    disconnect();
        //    return res;
        //}
    }
}
